package com.rency.mtds.manager.spi.enums;

import io.swagger.annotations.ApiModel;
import lombok.Getter;
import lombok.ToString;

import java.util.Arrays;
import java.util.Optional;

/**
 * 返回码
 * @author: caiyu.ren
 * Created on 2019/9/3 10:15
 * @version: V1.0.0
 * @since JDK 11
 */
@ApiModel("返回码")
@Getter
@ToString
public enum ReturnCode {

    SUCCESS("S000", "处理成功"),

    FAILED("F000", "处理失败"),
    ILLEGAL_PARAM("F001", "参数校验失败"),
    RECORD_NOT_FOUND("F002", "记录不存在"),
    ;

    private String code;

    private String msg;

    ReturnCode(String code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static ReturnCode get(String code){
        Optional<ReturnCode> optional = Arrays.stream(ReturnCode.values()).filter(kind -> kind.getCode().equalsIgnoreCase(code)).findFirst();
        return optional.orElse(null);
    }
}
